package com.sky.controller.user;

import com.alibaba.fastjson.JSONObject;
import com.sky.dto.UserLoginDTO;
import com.sky.pojo.AddressBook;
import com.sky.pojo.Category;
import com.sky.pojo.Dish;
import com.sky.result.Result;
import com.sky.service.user.UserService;
import com.sky.vo.DishItemVO;
import com.sky.vo.DishVO;
import com.sky.vo.SetmealVO;
import com.sky.vo.UserLoginVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Update;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "用户登录")
@RestController
@Slf4j
public class UserController {
    @Autowired
    private UserService userService;
    @ApiOperation("登录")
    @PostMapping("/user/user/login")
    public Result userLogin(@RequestBody UserLoginDTO userDto){
       // userDto.setLocation("104.06590100000005,30.65737199999999");
        UserLoginVO result = userService.login(userDto);
        return Result.success(result);
    }

   /* *//**
     * 新增用户地址
     * @param addressBook
     * @return
     *//*
    @PostMapping("/user/addressBook")
    public Result addAddressBood(@RequestBody AddressBook addressBook){
        log.info("要添加的内容为：{}",addressBook);
        userService.addAddressBook(addressBook);
        return Result.success();
    }
    @GetMapping("/user/addressBook/list")
    @ApiOperation("根据用户id获取用户所有的地址")
    public Result selectAddreeBoodList(){
        log.info("查询用户的地址：");
        List<AddressBook> list= userService.selectAddreeBoodList();
        return Result.success(list);
    }
    @PutMapping("/user/addressBook")
    @ApiOperation("修改用户的地址信息")
    public Result updateAddressBook(@RequestBody AddressBook addressBook){
        log.info("要修改的地址为：{}",addressBook);
        userService.updateAddressBook(addressBook);
        return Result.success();
    }
    @DeleteMapping
    @ApiOperation("根据id删除地址")
    public Result deleteAddressBook(int id){
        log.info("要删除的地址id为：{}",id);
        userService.deleteAddressBook(id);
        return Result.success();
    }

    @GetMapping("/user/addressBook/{id}")
    @ApiOperation("根据id查询回显")
    public Result selectAddressById(@PathVariable Long id){
        log.info("查询的id为：{}",id);
        AddressBook result = userService.selectAddressById(id);
        return Result.success(result);
    }
    @ApiOperation("查询默认地址")
    @GetMapping("/user/addressBook/default")
    public Result selectAddressDefult(){
        AddressBook address =  userService.selectDefault();
        return Result.success(address);
    }
    @ApiOperation("修改默认地址")
    @PutMapping("/user/addressBook/default")
    public Result updateAddressDefault(AddressBook addressBook){
        log.info("要修改的默认地址id为:{}",addressBook.getId());
        userService.updateAddressBook(addressBook);
        return Result.success();
    }*/

}
